//
//  WxTitleBottomV.m
//  TodayAnecdote
//
//  Created by weixin on 2017/9/27.
//  Copyright © 2017年 OKweixin2. All rights reserved.
//

#import "WxTitleBottomV.h"


@interface WxTitleBottomV ()


@property (nonatomic,assign)BOOL sta;

@end

@implementation WxTitleBottomV


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
      
        
        [self addSubview:self.BtnScroll];
        
        UIImageView *DownBtn = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-40, 5,30, 30)];
        DownBtn.image = [UIImage imageNamed:@"sy-label_more"];
        DownBtn.userInteractionEnabled = YES;
//        DownBtn.backgroundColor = WXColor;
        [self addSubview:DownBtn];
        
        UITapGestureRecognizer *tag = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(btn:)];
        [DownBtn addGestureRecognizer:tag];
        
    }
    return self;
}

-(void)btn:(UITapGestureRecognizer*)btn{
    
    if (self.block) {
        _block(self.btnState);
        self.btnState = !self.btnState;
    }
    
    
    CGAffineTransform  transform;
    
    if (self.sta==YES) {
        transform = CGAffineTransformRotate(btn.view.transform,-(M_PI/4.0));
    }else{
        transform = CGAffineTransformRotate(btn.view.transform,M_PI/4.0);
    }
    
    self.sta = !self.sta;
    
    [UIView beginAnimations:@"rotate" context:nil ];
    
    [UIView setAnimationDuration:0.3];
    
    [UIView setAnimationDelegate:self];
    
    [btn.view setTransform:transform];
    
    [UIView commitAnimations];
    
}

-(void)setArrTitle:(NSMutableArray *)arrTitle
{
    _arrTitle = arrTitle;
    self.BtnScroll.arrM = arrTitle;
}

-(OKBtnScroll*)BtnScroll
{
    if (_BtnScroll) {
        return _BtnScroll;
    }
    
    _BtnScroll = [[OKBtnScroll alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width-40, 40)];
    
    __weak typeof(self) weakself = self;
    
    [_BtnScroll setBlock:^(NSUInteger index) {
        if (_blcokIndex) {
            self.blcokIndex(index);
        }
    }];
    //        _BtnScroll.arrM = self.arrBtn;
    return _BtnScroll;
}
@end
